/**
 * 作者: wgx
 * 日期: 2025-03-05 11:32:02
 * 备注: 子嗣联姻的全服联姻信息
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class ServerMarryInfoModel extends BaseModel implements Model {
    public static final String LISTKEY = "server_id.child_id";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = false;// 是否需要额外的有序列表

    protected long id; // 数据库ID
    protected int serverId; // 服务器id
    protected long userId; // 玩家id
    protected long childId; // user_child_unmarried表的id
    protected long minEarnAdd; // 最低的城市收益
    protected long addTime; // 发布时间
    protected int sex; // 性别 (0女1男)

    public void reset() {
    }

    protected String getKey() {
        return "ServerMarryInfo." + serverId + "." + childId;
    }

    protected String getListKey() {
        return "ServerMarryInfo." + serverId;
    }

    protected String getListItemKey() {
        return childId + "";
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("server_marry_info"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // 数据库ID
        obj.put("serverId", serverId); // 服务器id
        obj.put("userId", userId); // 玩家id
        obj.put("childId", childId); // user_child_unmarried表的id
        obj.put("minEarnAdd", minEarnAdd); // 最低的城市收益
        obj.put("addTime", addTime); // 发布时间
        obj.put("sex", sex); // 性别 (0女1男)
        return obj;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public int getServerId() {
        return serverId;
    }

    public void putServerId(int serverId) {
        if (this.serverId != serverId) {
            this.serverId = serverId;
            updateRedisHashField(getKey(), "serverId", this.serverId);
        }
    }

    public void addServerId(int value) {
        this.serverId += value;
        updateRedisHashField(getKey(), "serverId", this.serverId);
    }

    public long getUserId() {
        return userId;
    }

    public void putUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            updateRedisHashField(getKey(), "userId", this.userId);
        }
    }

    public void addUserId(long value) {
        this.userId += value;
        updateRedisHashField(getKey(), "userId", this.userId);
    }

    public long getChildId() {
        return childId;
    }

    public void putChildId(long childId) {
        if (this.childId != childId) {
            this.childId = childId;
            updateRedisHashField(getKey(), "childId", this.childId);
        }
    }

    public void addChildId(long value) {
        this.childId += value;
        updateRedisHashField(getKey(), "childId", this.childId);
    }

    public long getMinEarnAdd() {
        return minEarnAdd;
    }

    public void putMinEarnAdd(long minEarnAdd) {
        if (this.minEarnAdd != minEarnAdd) {
            this.minEarnAdd = minEarnAdd;
            updateRedisHashField(getKey(), "minEarnAdd", this.minEarnAdd);
        }
    }

    public void addMinEarnAdd(long value) {
        this.minEarnAdd += value;
        updateRedisHashField(getKey(), "minEarnAdd", this.minEarnAdd);
    }

    public long getAddTime() {
        return addTime;
    }

    public void putAddTime(long addTime) {
        if (this.addTime != addTime) {
            this.addTime = addTime;
            updateRedisHashField(getKey(), "addTime", this.addTime);
        }
    }

    public void addAddTime(long value) {
        this.addTime += value;
        updateRedisHashField(getKey(), "addTime", this.addTime);
    }

    public int getSex() {
        return sex;
    }

    public void putSex(int sex) {
        if (this.sex != sex) {
            this.sex = sex;
            updateRedisHashField(getKey(), "sex", this.sex);
        }
    }

    public void addSex(int value) {
        this.sex += value;
        updateRedisHashField(getKey(), "sex", this.sex);
    }

}